package com.yuehuanghun.admin.core.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonFormat.Shape;
import com.yuehuanghun.admin.core.config.annotation.mybatislilu.CreateBy;
import com.yuehuanghun.admin.core.config.annotation.mybatislilu.CreateTime;
import com.yuehuanghun.admin.core.config.annotation.mybatislilu.UpdateBy;
import com.yuehuanghun.framework.annotation.Excel;
import com.yuehuanghun.framework.annotation.Excel.ColumnType;
import com.yuehuanghun.mybatis.milu.annotation.AttributeOptions;
import com.yuehuanghun.mybatis.milu.annotation.ExampleQuery;
import com.yuehuanghun.mybatis.milu.annotation.ExampleQuery.MatchType;
import com.yuehuanghun.mybatis.milu.annotation.alias.attr.UpdateTime;
import com.yuehuanghun.mybatis.milu.annotation.alias.id.SnowflakeId;

import lombok.Data;

/**
 * 岗位表 sys_post
 * 
 * @author yadmin
 */
@Data
@Entity
public class SysPost implements Serializable {
	private static final long serialVersionUID = 1L;

	/** 岗位序号 */
	@Excel(name = "岗位序号", cellType = ColumnType.NUMERIC)
	@SnowflakeId
	@JsonFormat(shape = Shape.STRING)
	private Long postId;

	/** 岗位编码 */
	@Excel(name = "岗位编码")
	@AttributeOptions(exampleQuery = @ExampleQuery(matchType = MatchType.CONTAIN))
	private String postCode;

	/** 岗位名称 */
	@Excel(name = "岗位名称")
	@AttributeOptions(exampleQuery = @ExampleQuery(matchType = MatchType.CONTAIN))
	private String postName;

	/** 岗位排序 */
	@Excel(name = "岗位排序")
	private String postSort;

	/** 状态（0正常 1停用） */
	@Excel(name = "状态", readConverterExp = "0=正常,1=停用")
	private String status;

	/** 创建者 */
	@CreateBy
	private String createBy;

	/** 创建时间 */
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@CreateTime
	private Date createTime;

	/** 更新者 */
	@UpdateBy
	private String updateBy;

	/** 更新时间 */
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@UpdateTime
	private Date updateTime;

	/** 备注 */
	private String remark;

	/** 用户是否存在此岗位标识 默认不存在 */
	@Transient
	private boolean flag = false;

	@ManyToMany
	@JoinTable(name = "sys_user_post", joinColumns = @JoinColumn(name = "post_id"), inverseJoinColumns = @JoinColumn(name = "user_id"))
	private List<SysUser> users;
	
	/** 请求参数 */
	@Transient
    private Map<String, Object> params;
	
	public Map<String, Object> getParams() {
		return params == null ? (params = new HashMap<>()) : params;
	}
}
